import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// 动态路由
import permissionsAsyncRouter from './modules/permissions'
import departmentsAsyncRouter from './modules/departments'
import employeesAsyncRouter from './modules/employees'
import salarysAsyncRouter from './modules/salarys'
import social_securitysAsyncRouter from './modules/social_securitys'
import attendancesAsyncRouter from './modules/attendances'
import approvalsAsyncRouter from './modules/approvals'
import settingsAsyncRouter from './modules/settings'
export const asyncRoutes = [
  // 先空着这里，后面来补充功能
  departmentsAsyncRouter,
  settingsAsyncRouter,
  employeesAsyncRouter,
  permissionsAsyncRouter,
  salarysAsyncRouter,
  social_securitysAsyncRouter,
  attendancesAsyncRouter,
  approvalsAsyncRouter
]
// 静态路由
export const constantRoutes = [
  {
    path: '/import',
    component: () => import('@/views/import/index.vue'),
    hidden: true
  },
  {
    path: '/demo',
    component: () => import('@/views/demo/parent'),
    hidden: true
  },
  {
    path: '/login',
    component: () => import(/* webpackChunkName:"login"*/'@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import(/* webpackChunkName:"404"*/'@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import(/* webpackChunkName:"Dashboard"*/'@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  }
  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // 默认路由模式是hash模式  ,到生产环境时,要改为history模式
  // 控制路由滚动行为  滚动到顶部
  scrollBehavior: () => ({ y: 0 }),
  // routes: [...constantRoutes, ...asyncRoutes]
  routes: [...constantRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
